package repository

import (
	"errors"

	"github.com/ce-exp/backend/mod/class/internal/entity"
	"github.com/ce-exp/backend/mod/class/internal/repository/query"
	"github.com/ce-exp/backend/mod/user/constant/errs"
	"github.com/tsingshaner/gin/shared"
	"gorm.io/gorm"
)

type Class struct {
	db *gorm.DB
}

func NewClass(db *gorm.DB) *Class {
	return &Class{db}
}

func (c *Class) GetClassByID(id shared.ID) (*entity.Class, error) {
	_, err := query.Class.Where(query.Class.ID.Eq(id)).First()

	if err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return nil, errors.Join(errs.Basic.DataNotFound, err)
		}

		return nil, errors.Join(errs.InternalServerError.DatabaseQuery, err)
	}

	return nil, nil
}
